<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
  .ui-datepicker table {
    border: 0;
  }
  .yform label{
    display:inline;
  }
</style>
<script type="text/javascript">
  $(function() {
    $("#form1").validationEngine();
    $(".datepicker").datepicker({ maxDate: 0 });
    $("#form1").submit(function(){
      if($("#form1").validationEngine("validate") && $("#goods_number").val()>0){
        $.ajax({
          type: "POST",
          url: "json_purchase.asp?action=add",
          data: $("#form1").serialize(),
          dataType: "json",
          success: function(msg){
            if(msg.bStatus){
              alert("新增成功");
              window.location.reload();
            }
          }
        });
      }
      return false;
    });
    var json,json_vendor,json_brand,json_class,json_goods,json_purchase,json_unit;
    var purchase_id;
    var unit_select,brand_select,class_select;
    purchase_id=$.query.get('purchase_id');
    Get_Purchase(purchase_id);

    //初始化供应商列表
    function Init_Vendor(){
      var vendor_option="";
      $.each(json_vendor,function(i,item){
        vendor_option+='<option value="'+item.vendor_id+'">'+item.vendor_name+'</option>';
      });
      $("#purchase_vendor").html(vendor_option);
    }
    function Init_Unit(){
      var unit_option="<select class='goods_unit' name='goods_unit'>";
      $.each(json_unit,function(i,item){
        unit_option+='<option value="'+item.unit_id+'">'+item.unit_name+'</option>';
      });
      unit_option+="</select>";
      return unit_option;
    }
    function Init_Class(){
      var class_option="<select class='goods_class' name='goods_class'>";
      $.each(json_class,function(i,item){
        class_option+='<option value="'+item.class_id+'">'+item.class_name+'</option>';
      });
      class_option+="</select>";
      return class_option;
    }
    function Init_Brand(){
      var brand_option="<select class='goods_brand' name='goods_brand'>";
      $.each(json_brand,function(i,item){
        brand_option+='<option value="'+item.brand_id+'">'+item.brand_name+'</option>';
      });
      brand_option+="</select>";
      return brand_option;
    }
    
    function Init_Goods(){
      var i=$("#goods_list>tbody>tr").length;
      var goods_tr="<tr>";
      i++;
      goods_tr+="<td><span class='goods_i'>"+i+"<span><input type='hidden' value='0' name='goods_id' /></td>";
      goods_tr+="<td>"+Init_Class(i)+"</td>";
      goods_tr+="<td><input type='text' class='goods_name validate[required]' name='goods_name' id='goods_name"+i+"' /></td>";
      goods_tr+="<td>"+Init_Brand(i)+"</td>";
      goods_tr+="<td><input type='text' class='goods_model' name='goods_model' size='10' value='' /></td>";
      goods_tr+="<td><input type='text' class='goods_spec' name='goods_spec' size='10' value='' /></td>";
      goods_tr+="<td>"+Init_Unit(i)+"</td>";
      goods_tr+="<td><input type='text' class='goods_quantity validate[required,custom[onlyNumber],min[1]]' name='goods_quantity' id='goods_quantity"+i+"' size='4' /></td>";
      goods_tr+="<td><input type='text' class='goods_unitprice validate[required,custom[number]]' name='goods_unitprice' id='goods_unitprice"+i+"' size='4' /></td>";
      goods_tr+="<td><input type='text' class='goods_price' name='goods_price' readonly='readonly' size='4' value='0' /></td>";
      goods_tr+="<td><input type='text' class='goods_memo' name='goods_memo' size='10' value='' /></td>";
      goods_tr+="<td><input type='button' class='del_goods' value='删除文具' /></td>";
      goods_tr+="</tr>";
      return goods_tr;
    }
    
    function Calc_Goods_Price($goods_tr){
      $goods_tr.find(".goods_price").val((tonumber($goods_tr.find(".goods_quantity").val())*tonumber($goods_tr.find(".goods_unitprice").val())).toFixed(2));
    }
    function Calc_Purchase_Price($goods_tbody){
      var purchase_price=0;
      $goods_tbody.find(".goods_price").each(function(){
        purchase_price+=tonumber($(this).val());
      });
      $("#purchase_price").val(purchase_price.toFixed(2));
    }
    function Refresh_Goods_List($goods_tr){
      var i;
      $goods_tr.each(function(i,item){
        i=$(this).prevAll().length;
        console.log(i);
        $(this).find(".goods_i").html(i);
        $(this).find(".goods_name").attr("id","goods_name"+i);
        $(this).find(".goods_unitprice").attr("id","goods_unitprice"+i);
        $(this).find(".goods_quantity").attr("id","goods_quantity"+i);
      });
    }
    
    $("#add_goods").click(function(){
      $("#goods_list").find("tbody").append(Init_Goods());
      $("#goods_number").val(parseInt($("#goods_number").val())+1);
    });
    $("#goods_list").delegate(".goods_quantity,.goods_unitprice", "keyup", function(){

//　　　　$(this).toggleClass("click");
      console.log($(this).val());
      Calc_Goods_Price($(this).closest("tr"));
      Calc_Purchase_Price($(this).closest("tbody"));
　　});
    $("#goods_list").delegate(".del_goods", "click", function(){
      $("#goods_number").val(parseInt($("#goods_number").val())-1);
      Refresh_Goods_List($(this).closest("tr").nextAll());
      $(this).closest("tr").remove();
　　});
    //通过ajax获得json数据
    function Get_Purchase(purchase_id){
      $.getJSON("json_purchase.asp?purchase_id="+purchase_id,function(data){
        if(data.bStatus){
          json=data;
          json_vendor=data.aVendor;
          json_unit=data.aUnit;
          json_brand=data.aBrand;
          json_class=data.aClass;
          json_purchase=data.dPurchase;
          json_goods=data.aGoods;
          Init_Vendor();
          unit_select=Init_Unit();
          brand_select=Init_Brand();
          class_select=Init_Class();
          $("#goods_list").find("tbody").append(Init_Goods());
        }else{
          //alert(data.sInfo);
          //$( "#dialog:ui-dialog" ).dialog( "destroy" );
          $( "#dialog-modal" ).html( '<p>'+data.sInfo+'</p>' ).dialog({
            height: 140,
            modal: true,
            //position: 'center',
            buttons: {
              "确定": function() {
                $( this ).dialog( "close" );
                $("#vessel").focus();
              }
            }

          });
        }
      });
    }
  });
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),3,5) then call JumpErrorPage(2)
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
  <div id="col3" role="main">
    <div id="col3_content" class="clearfix">
      <form id="form1" name="form1" method="post" class="yform" role="application">
          供货商：<select id="purchase_vendor" name="purchase_vendor">
          </select>

  进货日期：  <input type="text" class="datepicker validate[required]" size="10" readonly="readonly" name="purchase_date" id="purchase_date" value="<%=date()%>" />
  进货单号：  <input type="text" name="purchase_sn" id="purchase_sn" class='validate[required]' />
  进货联系人：  <input type="text" name="purchase_contact" size="4" id="purchase_contact" />
  已开票：  <input name="purchase_bill" id="purchase_bill" type="checkbox" value="1"/>
  备注：  <input type="text" name="purchase_memo" id="purchase_memo" size="10" />
  总金额：<input type="text" size="10" name="purchase_price" id="purchase_price" readonly="readonly" value="0" />
  <input name="goods_number" id="goods_number" type='hidden' value="1" />
        <div>
          <table id="goods_list" class="full">
            <thead>
              <tr>
                <th>序号</th>
                <th>分类</th>
                <th>文具名</th>
                <th>品牌</th>
                <th>型号</th>
                <th>规格</th>
                <th>单位</th>
                <th>数量</th>
                <th>单价</th>
                <th>金额</th>
                <th>备注</th>
                <th><input name="add_goods" id="add_goods" type="button" value="新增文具" /></th>
              </tr>
            </thead>
            <tbody>
            </tbody>
          </table>
        </div>
        <input type="submit" name="submit" value="新增这批文具" />
        <input name="reset" type="reset" value="重置" />
      </form> 
      <div>
        <table class="full">
          <thead>
            <tr>
              <th scope="col">分类</th>
              <th scope="col">文具</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>纸张</td>
              <td>A4打印纸,针式打印纸,照片打印纸</td>
            </tr>
            <tr>
              <td>耗材</td>
              <td>墨盒,硒鼓,色带,色带框,补充墨水</td>
            </tr>
            <tr>
              <td>笔/笔芯</td>
              <td>水笔,圆珠笔,铅笔,荧光笔,唛头笔,白板笔,粘性笔,自动铅笔,水笔芯,自动铅笔芯</td>
            </tr>
            <tr>
              <td>文件容器类</td>
              <td>杆棒夹,单片夹,插页文件夹,快劳夹,文件单/双夹,快劳夹内页,纽扣袋,拉链袋,文件座,文件柜,文件栏,档案盒</td>
            </tr>
            <tr>
              <td>电脑配件类</td>
              <td>电脑小配件,U盘,移动硬盘</td>
            </tr>
            <tr>
              <td>贵重办公用品</td>
              <td>打印机,传真机,碎纸机,考勤钟,复印机配件</td>
            </tr>
            <tr>
              <td>其他办公用品</td>
              <td>修正带,修正液,橡皮,长尾夹,票夹,文件装订夹,打孔器,大头针,订书机,订书针,回形针,起钉器,剪刀,胶水,电池,封箱带,透明胶布,美工刀,塑料绳,胶带切割器,双面胶,计算器,电话,插座,笔记本,复写纸,标签纸,告示贴,A4不干胶,考勤卡,纸篓,卫生纸,洗手液,洗洁精,纸杯,警告标识,红包,台历,台历架,便签盒,钢笔墨水,尺子,笔筒,</td>
            </tr>
          </tbody>
         </table>
      </div>
      <div>
      近期进货批次列表
        <table class="full">
          <thead>
            <tr>
              <th scope="col"></th>
              <th scope="col">序号</th>
              <th scope="col">批号</th>
              <th scope="col">供货商</th>
              <th scope="col">进货日期</th>
              <th scope="col">进货单号</th>
              <th scope="col">进货联系人</th>
              <th scope="col">总金额</th>
              <th scope="col">经手人</th>
              <th scope="col">开票</th>
              <th scope="col">备注</th>
            </tr>
          </thead>
          <tbody>
        <%
          set rs = Server.CreateObject("ADODB.Recordset")
          sql="select * from purchase_sql order by purchase_update desc"
          rs.open sql,conn,1,1
          do while not rs.eof
        %>
            <tr>
              <th class="sub" scope="row"><input type="checkbox" /></th>
              <th class="sub" scope="row"><%=rs.AbsolutePosition%></th>
              <td><a target="_blank" href="purchase_info.asp?purchase_id=<%=rs("purchase_id")%>"><%=rs("purchase_id")%></a></td>
              <td><%=rs("vendor_name")%></td>
              <td><%=rs("purchase_date")%></td>
              <td><%=rs("purchase_sn")%></td>
              <td><%=rs("purchase_contact")%></td>
              <td><%=rs("purchase_price")%></td>
              <td><%=rs("fullname")%></td>
              <td><%if rs("purchase_bill") then response.write("√")%></td>
              <td><%=rs("purchase_memo")%></td>
            </tr>
        <%
          rs.movenext()
        loop
        %>
          </tbody>
        </table>  
      </div>
    </div>
  </div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

